package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@Api(tags = "护理等级相关接口")
@RestController
@RequestMapping("/nursingLevel")
public class NursingLevelController extends BaseController {

    @Autowired
    private NursingLevelService nursingLevelService;

    @ApiOperation("查询所有护理等级")
    @GetMapping("/listAll")
    public ResponseResult getAllNursingLevel() {
        List<NursingLevelVo> nurList = nursingLevelService.getAllNursingPlan();
        return success(nurList);
    }

    @ApiOperation("新增护理等级")
    @PostMapping("/insert")
    public ResponseResult insert(
            @ApiParam(value = "护理等级数据传输对象", required = true)
            @RequestBody NursingLevelDto dto) {
        nursingLevelService.insert(dto);
        return success();
    }

    @ApiOperation("条件分页查询")
    @GetMapping("/listByPage")
    public ResponseResult<PageResponse<NursingLevelVo>> pageQuery(
            @ApiParam(name = "name", value = "护理等级名称") String name,
            @ApiParam(name = "status", value = "状态 0禁用 1启用") Integer status,
            @ApiParam(name = "pageNum", value = "当前页")
            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @ApiParam(name = "pageSize", value = "每页条数")
            @RequestParam(required = false, defaultValue = "10") Integer pageSize
    ) {
        PageResponse<NursingLevelVo> pageList = nursingLevelService.pageQuery(name, status, pageNum, pageSize);
        return success(pageList);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理等级")
    public ResponseResult getNursingPlanById(
            @ApiParam(name = "id", value = "护理等级id", required = true)
            @PathVariable Long id) {
        NursingLevelVo vo = nursingLevelService.getNursingPlanById(id);
        return ResponseResult.success(vo);
    }

    @PutMapping("/update")
    @ApiOperation("修改护理等级")
    public ResponseResult updateNursingPlan(
            @ApiParam(value = "修改护理等级数据传输对象", required = true)
            @RequestBody NursingLevelDto dto) {
        nursingLevelService.updateNursingPlan(dto);
        return ResponseResult.success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除护理等级")
    public ResponseResult deleteNursingPlan(
            @ApiParam(name = "id", value = "护理等级id", required = true)
            @PathVariable Long id) {
        nursingLevelService.deleteNursingPlan(id);
        return ResponseResult.success();
    }

    @ApiOperation("启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(
            @ApiParam(name = "id", value = "护理等级id", required = true)
            @PathVariable Long id,
            @ApiParam(name = "status", value = "护理等级状态", required = true)
            @PathVariable Integer status) {
        nursingLevelService.updateStatus(id, status);
        return ResponseResult.success();
    }
}
